package com.taoge.p4.common.config;

import com.taoge.p4.common.enums.RedisChannelEnum;
import com.taoge.p4.common.redisMessageListener.BrandRefreshSubscribe;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisConfig {
    @Resource
    private RedisConnectionFactory redisConnectionFactory;

    @Resource
    private BrandRefreshSubscribe brandRefreshSubscribe;

    @Bean
    RedisMessageListenerContainer redisMessageListenerContainer() {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.addMessageListener(brandRefreshSubscribe, new PatternTopic(RedisChannelEnum.BRAND_REFRESH_CHANNEL.getChannel()));
        container.setConnectionFactory(redisConnectionFactory);
        return container;
    }
}
